package com.fowo.api.syncAmazon.api;

import com.amazon.spapi.api.SellersApi;
import com.amazon.spapi.client.ApiException;
import com.amazon.spapi.model.sellers.GetMarketplaceParticipationsResponse;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fowo.api.datainterface.entity.DatainterfaceAuthority;
import com.fowo.api.datainterface.service.DatainterfaceAuthorityService;
import com.fowo.api.syncAmazon.util.AmazonUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class SellersService {

    @Resource
    private DatainterfaceAuthorityService datainterfaceAuthorityBaseService;
    @Resource
    private AmazonUtil amazonUtil;

    /**
     * 获取账号商城信息
     * @param refreshToken
     * @return
     * @throws ApiException
     */
    public GetMarketplaceParticipationsResponse getMarketplaceParticipations(String refreshToken,String endpoint,String region) throws ApiException {
        DatainterfaceAuthority entityAuthority = datainterfaceAuthorityBaseService.getOne(Wrappers.<DatainterfaceAuthority>lambdaQuery().eq(DatainterfaceAuthority::getAppCode,"Amazon"), false);

        SellersApi sellersApi = amazonUtil.getSellersApi(entityAuthority,refreshToken,endpoint,region);

        return sellersApi.getMarketplaceParticipations();
    }

}
